import 'package:flutter/material.dart';
import '../../models/order_detail_model.dart';
import '../manger/user_manger.dart';
import 'package:ninetyfour/l10n/app_localizations.dart';

class GlobalConfig {
  // 颜色配置
  static Color mainBgColor = Color(int.parse('0xFFF8F6F7'));
  static Color labelColor = Color(int.parse('0xFF505050'));
  static Color label2Color = Color(int.parse('0xFF000000'));
  static Color label666Color = Color(int.parse('0xFF666666'));
  static Color bgColor = Color(int.parse('0xFFF6F6F6'));
  static Color label3Color = Color(int.parse('0xFF4C4C4C'));
  static Color label4Color = Color(int.parse('0xFF898989'));
  static Color grayColor = Color(int.parse('0xFFACACAC'));
  static Color redColor = Color(int.parse('0xFFEC3A22'));
  static Color titleSelectColor = Color(int.parse('0xFF5657BC'));
  static Color titleRedColor = Color(int.parse('0xFFF61F03'));
  static Color titleBlueColor = Color(int.parse('0xFF5D5FEE'));
  static Color title78Color = Color(int.parse('0xFF787FC5'));

 // 中文转换函数
  // RGBA 颜色生成方法
  static Color rgba(double r, double g, double b, double a) {
    return Color.fromRGBO(r.toInt(), g.toInt(), b.toInt(), a);
  }

  // 屏幕相关方法
  static double getStatusBarHeight(BuildContext context) {
    return MediaQuery.of(context).padding.top;
  }

  // 顶部安全区高度
  static double getSafeAreaInsetsTop(BuildContext context) {
    return MediaQuery.of(context).padding.top;
  }

  // 底部安全区高度
  static double getSafeAreaInsetsBottom(BuildContext context) {
    return MediaQuery.of(context).padding.bottom;
  }

  // 屏幕尺寸
  static double getScreenWidth(BuildContext context) {
    return MediaQuery.of(context).size.width;
  }

  static double getScreenHeight(BuildContext context) {
    return MediaQuery.of(context).size.height;
  }

  // 导航栏高度
  static const double navContentBarHeight = 44.0;

  // 底部 tabBar 栏高度（不包含安全区）
  static const double tabBarHeight = 49.0;

  // 底部导航栏高度（包括安全区）
  static double getTabBarHeight(BuildContext context) {
    return getSafeAreaInsetsBottom(context) + tabBarHeight;
  }

  // 状态栏 + 导航栏的高度
  static double getNavigationBarAndStatusBarHeight(BuildContext context) {
    return navContentBarHeight + getStatusBarHeight(context);
  }
}


class UrlConfig {
  // static const String baseUrl = 'https://m.test.94lives.com'; 
  static const String baseUrl = 'https://m.94lives.com'; 
  // static const String baseUrl = 'http://192.168.3.24:8080'; 

  static String pinjie(BuildContext context) {
    return '${getTabsParam(context)}/Tabs/';
  }

  static String privacyPolicyURL(BuildContext context) =>
      '$baseUrl${pinjie(context)}NewsDetail?access=86&articleId=6${_getLanguageParam(context)}'; 

  static String payProtocalURL(BuildContext context) =>
      '$baseUrl${pinjie(context)}NewsDetail?access=86&articleId=7${_getLanguageParam(context)}'; 

  static String mianURL(BuildContext context) =>
      '$baseUrl${pinjie(context)}NewsDetail?access=86&articleId=5${_getLanguageParam(context)}'; 

  static String zhuxiaoURL(BuildContext context) =>
      '$baseUrl${pinjie(context)}NewsDetail?access=86&articleId=93${_getLanguageParam(context)}'; 

  static String tuikuanURL(BuildContext context) =>
      '$baseUrl${pinjie(context)}NewsDetail?access=86&articleId=29${_getLanguageParam(context)}'; 

  static String fuwuURL(BuildContext context) =>
      '$baseUrl${pinjie(context)}NewsDetail?access=86&articleId=4${_getLanguageParam(context)}'; 

  static String lianxiURL(BuildContext context) =>
      '$baseUrl${pinjie(context)}NewsDetail?access=86&articleId=28${_getLanguageParam(context)}'; 

  static String zfURL(BuildContext context) =>
      '$baseUrl${pinjie(context)}NewsDetail?access=86&articleId=21${_getLanguageParam(context)}'; 

  static String fuinURL(BuildContext context) =>
      '$baseUrl/appProcess?articleId=115${_getLanguageParam(context)}'; 

  static String yhcxURL(BuildContext context) =>
      '$baseUrl${pinjie(context)}salesPromotion?'; 

  static String _getLanguageParam(BuildContext context) {
    if (isSimplifiedChinese()) {
      return '&language_app=0';
    } else {
      return '&language_app=2'; // 英文
    } 
  }

  static String getTabsParam(BuildContext context) {
    if (!isSimplifiedChinese()) {
      if (isTraditionalChinese()) {
        return '/zh-hant';
      } else {
        return '/en';
      }
    } else {
      return '';
    } 
  }

  static String buildUrlString(String price, UseepayModel? model,BuildContext context) {
    var urlString = '$baseUrl${getTabsParam(context)}/payments?userid_app=${UserInfos.shared.userId}&price_app=$price';

    if (model?.surname != null) {
      final encodedSurname = Uri.encodeComponent(model!.surname!);
      urlString += '&surname_app=$encodedSurname';
    }

    if (model?.givenName != null) {
      final encodedGivenName = Uri.encodeComponent(model!.givenName!);
      urlString += '&givenName_app=$encodedGivenName';
    }

    if (model?.email != null) {
      final encodedEmail = Uri.encodeComponent(model!.email!);
      urlString += '&email_app=$encodedEmail';
    }

    return urlString;
  }
}


